package com.jjlin.chapter_5;

import java.util.*;
public class CD131 {

    //找到字符串的最长无重复字符子串
    public static int maxUnique(int[] nums, int n){
        if(nums == null || n < 1)
            return 0;
        Map<Integer, Integer> map = new HashMap<>();
        int res = 0;
        for(int start = 0, end = 0; end < n; end++){
            int num = nums[end];
            if(map.containsKey(num)){
                start = Math.max(start, map.get(num));//更新start
            }
            res = Math.max(res, end - start + 1);//更新最大长度
            map.put(num, end + 1);
        }
        return res;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums = new int[n];
        for(int i = 0; i < n; i++)
            nums[i] = sc.nextInt();
        System.out.println(maxUnique(nums, n));
    }
}
